<template>
  <order-address v-bind="$attrs"
                 :table-columns="tableColumns"
                 :table-data="tableData"
                 @inputVal="currentValEvent"
                 v-on="$listeners" />
</template>

<script>
import { receivingAddress as receivingAddressApi } from "@/api/index";
import OrderAddress from "./index.vue";
export default {
  name: "ConsigneeInfo",
  components: {
    OrderAddress
  },
  props: {
    customerId: [Number],
    filters: Object
  },
  data () {
    return {
      tableColumns: [
        { label: "收货方", name: "consigneeName" },
        { label: "收货地址", name: "address" },
        { label: "省市区", name: "addressCodeList", type: "address" },
        { label: "联系人", name: "contactName" },
        { label: "联系电话", name: "contactMobile" }
      ],
      tableData: []
    };
  },
  computed: {
    params () {
      return {
        ...this.filters,
        [this.$attrs.type]: this.$attrs.value
      }
    }
  },
  methods: {
    async currentValEvent (val) {
      await this.$emit("update:value", val);
    },
    async getList () {
      if (this.customerId) {
        let { code, data } = await receivingAddressApi.search({
          status: 1,
          size: 5,
          customerId: this.customerId,
          ...this.params
        });
        if (code !== 0 || !data) return;
        this.tableData = data.records;
      } else {
        this.tableData = [];
      }
    }
  }
};
</script>
